package function;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Add implements Function{
    @Override
    public void work(BookList bookList) {
        System.out.println("增加图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入添加的图书名字");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getOnNum(); i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                System.out.println("已存在该图书,不予添加");
                return;
            }
        }
        System.out.println("请输入图书作者");
        String author = scanner.nextLine();
        System.out.println("请输入图书类型");
        String type = scanner.nextLine();
        System.out.println("请输入图书价格");
        double price = scanner.nextDouble();
        Book book = new Book(name,author,type,price);
        bookList.setBook(bookList.getOnNum(), book);
        bookList.setOnNum(bookList.getOnNum()+1);
    }
}
